#ifndef OLLAMAAPI_H
#define OLLAMAAPI_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>

class OllamaAPI : public QObject
{
    Q_OBJECT
public:
    static int s_Id;
    explicit OllamaAPI(QObject *parent = nullptr);
    void sendRequest(const QString &message, const QString &conversationId = "");

signals:
    void responseReceived(const QString &response, const QString &conversationId);
    void streamResponseStarted(const QString &chunk, const QString &conversationId);
    void streamResponseReasoningContent(const QString &chunk, const QString &conversationId);
    void streamResponseReceived(const QString &chunk, const QString &conversationId);
    void responseFinished(const QString &conversationId);
private slots:
    void onReplyFinished();
    void onReadyRead(); // 读取流式数据

private:
    QNetworkAccessManager *manager;
    QNetworkReply *streamReply;
    QMap<QString,QStringList> mapHistroy;
    QString curConversationId;
    QString responseText;
    bool bStream;
    bool bShowThink;
};

#endif // OLLAMAAPI_H
